package Servlet;

import Bean.User;
import Dao.UserDao;
import Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-08
 * Time: 11:29
 */
//单个用户注销
@WebServlet("/UserDeleteServlet")
public class UserDeleteServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("application/json;charset=utf8");
        String UserId = req.getParameter("userId");
        //单删
        boolean ok = userService.deleteById(UserId);
        if(ok) {
            System.out.println(1);
            req.setAttribute("status", "success");
            req.setAttribute("message", "删除成功");
            req.setAttribute("redirectUrl", "UserList?pageNo=1");
            req.setAttribute("waitSeconds", 3);
        } else {
            req.setAttribute("status", "error");
            req.setAttribute("message", "删除失败,请检查数据库");
            req.setAttribute("redirectUrl", "UserList?pageNo=1");
            req.setAttribute("waitSeconds", 3);
        }
        req.getRequestDispatcher("skip.jsp").forward(req,resp);
    }
}
